package com.ludum.game.collision;

import java.util.LinkedList;
import com.badlogic.gdx.math.Vector2;


public class CollisionManager {
	private static CollisionManager instance = null;

	LinkedList<RectangleShape> shapeList;
	
	private CollisionManager(){
		shapeList = new LinkedList<RectangleShape>();
	}
	
	public static CollisionManager getInstance(){
		if(instance == null){
			instance = new CollisionManager();	
		}
		return instance;
	}
	
	public RectangleShape newRectangleShape(Vector2 pos, Vector2 size){
		RectangleShape shape = new RectangleShape(pos, size);
		shapeList.add(shape);
		return shape;
	}
	
	public Vector2 isInCollision(RectangleShape shape, Vector2 displacement){
		Vector2 newDisplacement = displacement.cpy();
		for(RectangleShape s: shapeList){
			if(s != shape){
				if(shape.testCollision(s,newDisplacement)){
					newDisplacement = shape.resolveCollision(s, newDisplacement);
				}
			}
		}
		return newDisplacement;
	}
}
